package jd.controller;

import jd.pojo.Electronic;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.Date;

@Controller
@RequestMapping("/JD")
public class ElectronicServlet {

    @RequestMapping("/add")
    public String add() {
        System.out.println("添加信息！！！");
        return "add";
    }

    /**
     * 保存信息
     * @param model
     * @param type
     * @param price
     * @return
     */
    @RequestMapping("/save")
    public String save(Model model, @RequestParam String type, double price){

        Electronic electronic = new Electronic();
        electronic.setId(4);
        electronic.setType(type);
        electronic.setPrice(price);
        electronic.setTime(new Date());

        model.addAttribute("Info",electronic);
        System.out.println("添加成功！");

        //跳转至save.jsp
        return "save";
    }
}